package com.mine.site.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mine.site.dao.YifuDao;
import com.mine.site.model.Commodity;





@SuppressWarnings("unused")
@WebServlet("/YifuServlet")
public class YifuServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("utf-8");
		
		
		HttpSession session = request.getSession();
		
		
		ServletContext ctx = request.getServletContext();

		PrintWriter out =  response.getWriter();
		
		String method = request.getParameter("m");
		if("clnz".equals(method)){
			this.clnz(request, response);
		}if("lyq".equals(method)){
			this.lyq(request, response);
		}if("nantx".equals(method)){
			this.nantx(request, response);
		}if("nvtx".equals(method)){
			this.nvtx(request, response);
		}if("jpnk".equals(method)){
			this.jpnk(request, response);
		}if("jonk".equals(method)){
			this.jonk(request, response);
		}if("xlbx".equals(method)){
			this.xlbx(request, response);
		}if("cjwt".equals(method)){
			this.cjwt(request, response);
		}if("clnanz".equals(method)){
			this.clnanz(request, response);
		}
		else{
			this.list(request, response);
		}
	}

	private void clnanz(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		YifuDao dao = new YifuDao();
		List<Commodity> Commo_clnanz = dao.findAll_clnanz();
		request.setAttribute("CommoList", Commo_clnanz);
		request.setAttribute("text", "������װ");
		request.getRequestDispatcher("clnz.jsp").forward(request, response);
	}

	private void cjwt(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		YifuDao dao = new YifuDao();
		List<Commodity> Commo_cjwt = dao.findAll_cjwt();
		request.setAttribute("text", "��������");
		request.setAttribute("CommoList", Commo_cjwt);
		request.getRequestDispatcher("clnz.jsp").forward(request, response);
	}

	private void xlbx(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		YifuDao dao = new YifuDao();
		List<Commodity> Commo_xlbx = dao.findAll_xlbx();
		request.setAttribute("CommoList", Commo_xlbx);
		request.setAttribute("text", "��������");
		request.getRequestDispatcher("clnz.jsp").forward(request, response);
	}

	private void jonk(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		YifuDao dao = new YifuDao();
		List<Commodity> Commo_jonk = dao.findAll_jonk();
		request.setAttribute("text", "��Ʒ�п�");
		request.setAttribute("CommoList", Commo_jonk);
		request.getRequestDispatcher("clnz.jsp").forward(request, response);
		
	}

	private void jpnk(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		YifuDao dao = new YifuDao();
		List<Commodity> Commo_jpnk = dao.findAll_jpnk();
		request.setAttribute("text", "��ƷŮ��");
		request.setAttribute("CommoList", Commo_jpnk);
		request.getRequestDispatcher("clnz.jsp").forward(request, response);
		
	}

	private void nvtx(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		YifuDao dao = new YifuDao();
		List<Commodity> Commo_nvtx = dao.findAll_nvtx();
		request.setAttribute("text", "Ůʿ����");
		request.setAttribute("CommoList", Commo_nvtx);
		request.getRequestDispatcher("clnz.jsp").forward(request, response);
		
	}

	private void nantx(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		YifuDao dao = new YifuDao();
		List<Commodity> Commo_nantx = dao.findAll_nantx();
		request.setAttribute("text", "��ʿ����");
		request.setAttribute("CommoList", Commo_nantx);
		request.getRequestDispatcher("clnz.jsp").forward(request, response);
		
	}

	private void lyq(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		YifuDao dao = new YifuDao();
		List<Commodity> Commo_lyq = dao.findAll_lyq();
		request.setAttribute("CommoList", Commo_lyq);
		request.setAttribute("text", "����ȹ");
		request.getRequestDispatcher("clnz.jsp").forward(request, response);
	}

	private void clnz(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		YifuDao dao = new YifuDao();
		List<Commodity> Commo_clnz = dao.findAll_clvz();
		request.setAttribute("CommoList", Commo_clnz);
		request.setAttribute("text", "����Ůװ");
		request.getRequestDispatcher("clnz.jsp").forward(request, response);
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
	
	private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		
	}
	

	
	
	
	
	

	private Commodity wrapUser(HttpServletRequest request) {
		Commodity u = new Commodity();
		u.setNumber(Integer.parseInt(request.getParameter("Number")));
		u.setName(request.getParameter("Name"));
		u.setTitle(request.getParameter("Title"));
		u.setPrice(request.getParameter("Price"));
		u.setUrl(request.getParameter("Url"));
		u.setImg_1(request.getParameter("Img_1"));
		u.setImg_2(request.getParameter("Img_2"));
		u.setMinute(request.getParameter("Minute"));
		u.setType(request.getParameter("Type"));
		return u;
	}
}
